<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<base href="<%=basePath%>">

	<title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
    <link rel="stylesheet" type="text/css"
        href="./css/idangerous.swiper.css">
     -->
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/styles.css">

	<script src="${pageContext.request.contextPath}/js/jquery-1.8.3.min.js"></script>
	<script src="${pageContext.request.contextPath}/js/jquery.fullpage.min.js"></script>

	<script type="text/javascript">
        $(function() {
            $('#fullpage').fullpage();
        });

		/*  	$("input[type=checkbox]:checked").each(function(){

		 alert($(this).attr('value'));
		 });  */
		/*   var selectChks = $("input[type=checkbox][name=productItem]:checked"); */
        var sum=0;
        var c =new Array();
        var a =new Array();
        var limit=new Array();
        function doCheck(obj, i, adwards_number)
        {
            c[i] = c[i] || 0;
            limit[i]=adwards_number;
			/* alert($(obj).attr('name')); */
            obj.checked?c[i]++:c[i]--;
            if(c[i]>limit[i]){
                obj.checked=false;
                alert("您只有"+limit[i]+"张票哦");
                c[i]--;
            }


        }

        function count(i )
        {

            var temp= document.getElementsByName("adw_number") ;

            sum=0;
            for(j=0;j<i;j++){
                sum+= parseInt(temp[j].value);
            }

            var nums = 0;
            var chk = $("input[type=checkbox]");
            for (var m = 0; m < chk.length; m++) {
                if(chk[m].checked){
                    nums++;
                }

            }
            //如果总票数不等于每个奖项设定的票数和，则无法提交
            if(nums<sum||sum<nums){
                alert("选中票数"+nums+" 应投总票数"+sum);
                return false;
            }
            document.getElementById("form").submit();
        }

	</script>

</head>

<body>


<c:forEach items="${datalist}" var="awardsInfo" varStatus="i">
	<input type="hidden" value="${awardsInfo.adwards_number}" name="adw_number">
</c:forEach>
<form action="user/insert" method="post" id="form">
	<div class="daohang">
		<div class="logo"><a href="toindex"><img src="./image/logo.png"></a></div>
		<div class="nav">
			<div class="dh6">
				<a href="">用户：${sessionScope.user.user_name}</a>
			</div>
			<div class="dh7">
				<input type="button" value="提交" onclick="count(${fn:length(datalist)})">
			</div>
		</div >

	</div>
	<!-- banner -->
	<!-- Slider-starts-Here -->

	<div id="fullpage">

		<c:forEach items="${datalist}" var="awardsInfo" varStatus="i">

			<div class="section">
				<div class="main" style="padding-top:90px;">
					<div class="award_number_message" style="font-size: 16px; color: gray; padding-left: 20px">您拥有 ${awardsInfo.adwards_number}张票</div>
					<center>
						<h1 style="font-size: 28px; font-family:Microsoft YaHei; color: #5cb85c;">${awardsInfo.adwards_name}</h1>
						<div class="con">
							<c:if test="${awardsInfo.adwards_type==1}">
								<c:forEach items="${awardsInfo.cand_users}" var="user">
									<div class="cow">
										<input type="checkbox" name="${awardsInfo.adwards_name}" value="${user.user_name}"
											   onclick="doCheck(this, ${i.index}, ${awardsInfo.adwards_number})"
											   style="width: 25px;height: 25px; margin: 40px auto;">
											${user.user_name}
									</div>
								</c:forEach>
							</c:if>
							<c:if test="${awardsInfo.adwards_type==2}">
								<c:forEach items="${awardsInfo.cand_departs}" var="depart">
									<div class="cow">
										<input type="checkbox" name="${awardsInfo.adwards_name}" value="${depart.depart_name}"
											   onclick="doCheck(this, ${i.index}, ${awardsInfo.adwards_number})"
											   style="width: 25px;height: 25px; margin: 40px auto;">
											${depart.depart_name}
									</div>
								</c:forEach>
							</c:if>
						</div>
					</center>
				</div>
			</div>
		</c:forEach>
	</div>
</form>
</body>

</html>
